package com.cn.lyl.lawyer.controller;

import com.cn.lyl.lawyer.model.entity.ServiceTypeModel;
import com.cn.lyl.lawyer.model.vo.ServiceTypeVo;
import com.cn.lyl.lawyer.service.ServiceService;
import com.cn.lyl.lawyer.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/service")

public class ServiceController {

    @Autowired
    private ServiceService serviceService;

    @PostMapping("/add")
    public Object add(ServiceTypeVo serviceTypeVo){
        serviceService.add(serviceTypeVo);
        return CommonResult.success(null);
    }

    @PostMapping("/delete")
    public Object delete(Integer id){
        serviceService.delete(id);
        return CommonResult.success(null);
    }

    @PostMapping("/edit")
    public Object edit(ServiceTypeVo serviceTypeVo){
        serviceService.change(serviceTypeVo);
        return CommonResult.success(null);
    }

    @GetMapping("/list")
    public Object findAll(ServiceTypeVo serviceTypeVo){
        List<ServiceTypeVo> all = serviceService.findAll(serviceTypeVo);
        Map map = new HashMap();
        map.put("count",serviceService.getCount(serviceTypeVo));
        map.put("list",all);
        return CommonResult.success(map);
    }

    @GetMapping("/findInfo")
    public Object findById(Integer id){
        ServiceTypeVo byId = serviceService.findById(id);
        return CommonResult.success(byId);
    }

    @GetMapping("/type")
    public Object findRole(){
        List<ServiceTypeModel> allType = serviceService.findAllType();
        return CommonResult.success(allType);
    }
}
